package factories;

import phone.Phone;
import phone.PhoneAmerican;
import phone.PhoneFrench;

public class PhoneFactory {
	
	/**
	 * Creates a Phone with the format of the specified country as a String and validates it
	 * @param type - the country phone nr format ; nr -  the actual phone nr
	 * @return new Phone of the specified type;
	 * @return null if the type specified is inexistent or the validation failed
	 */
	public static Phone createPhone(String type,Long nr){
		Phone ret;
		if (type.equals("american")){
			ret=new PhoneAmerican(nr);
			return ret.valid(nr)?ret:null;
		}
		if (type.equals("french")){
			ret=new PhoneFrench(nr);
			return ret.valid(nr)?ret:null;
		}
		return null;
	}
}
